package com.example.alarm;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;


public class MainActivity extends Activity implements OnClickListener {

    TextView time1;
    TextView time2;
    TextView time3;
    Button music;
    Button aggress;
    private int mhour;
    private int mminute;

    static final int TIME_DIALOG_TIME1 = 1;

    static final int TIME_DIALOG_TIME2 = 2;

    static final int TIME_DIALOG_TIME3 = 3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        time1 = (TextView) findViewById(R.id.time1);
        time1.setBackgroundResource(R.drawable.click_color);
        time2 = (TextView) findViewById(R.id.time2);
        time2.setBackgroundResource(R.drawable.click_color);
        time3 = (TextView) findViewById(R.id.time3);
        time3.setBackgroundResource(R.drawable.click_color);
        music = (Button) findViewById(R.id.music);
        aggress = (Button) findViewById(R.id.aggress);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.time1:
                showDialog(TIME_DIALOG_TIME1);
                break;
            case R.id.time2:
                showDialog(TIME_DIALOG_TIME2);
                break;
            case R.id.time3:
                showDialog(TIME_DIALOG_TIME3);
                break;
        }

    }

    public void onClick_Select_aggression(View v) {
        // TODO Auto-generated method stub
        Dialog dialog = onCreateDialogSingleChoiceAggress();
        dialog.show();

    }

    public void onClick_Select_music(View v) {

        Dialog dialog = onCreateDialogSingleChoiceMusic();
        dialog.show();

    }


    public Dialog onCreateDialogSingleChoiceAggress() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        CharSequence[] array = {"Light", "Medium", "High"};
        builder.setTitle("Select Aggression Level")
                .setSingleChoiceItems(array, 1, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })

                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });

        return builder.create();
    }

    public Dialog onCreateDialogSingleChoiceMusic() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        CharSequence[] array = {"Ultrasong 1", "Ultrasong 2", "Signalisation 1", "Signalisation 2"};
        builder.setTitle("Select Sound")
                .setSingleChoiceItems(array, 1, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                })


                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });

        return builder.create();
    }


    private TimePickerDialog.OnTimeSetListener mTimeSetListener =
            new TimePickerDialog.OnTimeSetListener() {
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    mhour = hourOfDay;
                    mminute = minute;
                    updatetime();
                }


                private void updatetime() {
                    time1.setText(
                            new StringBuilder()
                                    .append(pad(mhour)).append(":")
                                    .append(pad(mminute)));

                }

                private String pad(int c) {
                    if (c >= 10)
                        return String.valueOf(c);
                    else
                        return "0" + String.valueOf(c);
                }

            };

    private TimePickerDialog.OnTimeSetListener mTimeSetListener2 =
            new TimePickerDialog.OnTimeSetListener() {
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    mhour = hourOfDay;
                    mminute = minute;
                    updatetime();
                }

                private void updatetime() {

                    time2.setText(
                            new StringBuilder()
                                    .append(pad(mhour)).append(":")
                                    .append(pad(mminute)));
                }

                private String pad(int c) {
                    if (c >= 10)
                        return String.valueOf(c);
                    else
                        return "0" + String.valueOf(c);
                }

            };

    private TimePickerDialog.OnTimeSetListener mTimeSetListener3 =
            new TimePickerDialog.OnTimeSetListener() {
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    mhour = hourOfDay;
                    mminute = minute;
                    updatetime1();
                }

                private void updatetime1() {

                    time3.setText(
                            new StringBuilder()
                                    .append(pad(mhour)).append(":")
                                    .append(pad(mminute)));
                }

                private String pad(int c) {
                    if (c >= 10)
                        return String.valueOf(c);
                    else
                        return "0" + String.valueOf(c);
                }
            };

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {

            case TIME_DIALOG_TIME1:
                return new TimePickerDialog(this,
                        mTimeSetListener, mhour, mminute, false);
            case TIME_DIALOG_TIME2:
                return new TimePickerDialog(this,
                        mTimeSetListener2, mhour, mminute, false);
            case TIME_DIALOG_TIME3:
                return new TimePickerDialog(this,
                        mTimeSetListener3, mhour, mminute, false);

        }
        return null;
    }


}
